08. Demo: Forecast Stock Prices Using GBM
Forecasting Stock Prices Using GBM
PRDTM2-787 AI Trading C4 L3 Demo 1
Forecasting Future Stock Prices Using Geometric Brownian Motion
Harnessing the power of Python, stock prices can be forecasted using Geometric Brownian Motion (GBM) with Numpy and SciPy packages.
Key Concepts and Calculations
- Geometric Brownian Motion:
- Described by a stochastic differential equation.
- Parameters include:
- Mu: Indicates momentum or drift.
- Sigma: Represents volatility.
- Future Price Forecast:
- Formula calculates the stock price at a future time,
t, using the current stock priceS_0,Mu, andSigma. - Expected value at future time
tis given byS_0 * e^(Mu * t).
- Formula calculates the stock price at a future time,
- Confidence Interval Calculation:
- Logarithmic price differences show normal distribution.
- Mean:
Mu - 0.5 * Sigma^2 * t. - Standard deviation:
Sigma * sqrt(t).
Implementation Steps
- Import Packages: Numpy & SciPy.
- Define GBM Class:
- Initialize model parameters to default invalid values.
- Forecast Function:
- Input current price, future time, and confidence level.
- Outputs expected price and confidence interval.
Practical Example
- Scenario:
- Current stock price: $100.
- Momentum: 25%, Volatility: 10%.
- Future price in 6 months: Expected $113, with 90% confidence in $100.62 to $126.97 range.
Simulating Trajectories of a GBM
PRDTM2-787 AI Trading C4 L3 Demo 2
Simulating Stock Prices with Geometric Brownian Motion (GBM)
Understanding how to simulate stock price trajectories using Geometric Brownian Motion (GBM) is essential for evaluating trading strategies. This guide walks through:
Purpose of Simulating Trajectories:
- Models stock prices as GBM to identify potential weaknesses in trading strategies.
- Recognizes the historical stock price trajectory as just one possible path.
Key Mathematical Concepts:
- Utilizes a stochastic differential equation defining GBM.
- Parameters:
- Mu: Represents drift or momentum.
- Sigma: Indicates volatility.
- WT: Brownian motion, a series of normally distributed increments.
Programming Approach:
- Import necessary Python packages.
- Define a Class:
GBMclass to simulate GBM. - Simulation Function: Generates specified number of trajectories over given time steps.
Real-World Application:
- Simulate five potential price paths over three years for a stock with 25% momentum and 10% volatility.
This approach allows learners to understand the randomness and opportunities within stock behavior, preparing for real-world trading and risk management.